/*
 * @Author: liyin 2179253556@qq.com
 * @Date: 2023-04-17 09:53:22
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-05-13 16:46:31
 * @FilePath: user.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// @src/store/user.ts
import { defineStore } from 'pinia'
// import { logout } from '@/api/user'
import { ref } from 'vue';

export const useUserStore = defineStore('user', () => {
  const token = ref("")
  const userInfo = ref({} as any)
  const SET_TOKEN = (name: string) => {
    token.value = name
    sessionStorage.setItem("Token", name)
  }
  const SET_INFO = (user: any) => {
    sessionStorage.setItem("user", JSON.stringify(user))
    userInfo.value = user
  }
  const remove = async () => {
    // await logout()
    localStorage.clear()
    sessionStorage.clear()
    SET_INFO({} as any)
    SET_TOKEN('')
  }
  return {
    persist: true,
    token,
    userInfo,
    remove,
    SET_TOKEN,
    SET_INFO
  }
})